package group.igfd.manager.biz.controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import group.igfd.manager.biz.entity.BrandsEntity;
import group.igfd.manager.biz.entity.CategoriesEntity;
import group.igfd.manager.biz.entity.TagHotEntity;
import group.igfd.manager.biz.entity.TagStyleEntity;
import group.igfd.manager.biz.model.BrandModel;
import group.igfd.manager.biz.model.BuyerUser;
import group.igfd.manager.biz.model.TagHotModel;
import group.igfd.manager.biz.model.TagStyleModel;
import group.igfd.manager.biz.service.*;
import group.igfd.manager.biz.utils.AlidayuConstant;
import group.igfd.manager.biz.utils.AlidayuUtil;
import group.igfd.manager.biz.utils.SpringContextUtil;
import group.igfd.manager.biz.utils.ToolUtil;
import io.renren.common.utils.R;
import io.renren.common.utils.SpringContextUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/biz/common")
@Api(tags = {"A000 / 常用接口"})
public class CommonController {
    @Autowired
    private BrandsService brandsService;

    @Autowired
    private CategoriesService categoriesService;

    @Autowired
    private UsersService usersService;

    @Autowired
    private TagHotService tagHotService;

    @Autowired
    private TagStyleService tagStyleService;

    @GetMapping("/getBrands")
    @ApiOperation("获取品牌列表")
    public R getBrands() {
        EntityWrapper<BrandsEntity> ew = new EntityWrapper<>();
        ew.eq("auth_flag", "1");
        ew.eq("del_flag", "0");
        ew.orderBy("fix", true);

        List<BrandsEntity> list = brandsService.selectList(ew);
        List<BrandModel> brands = new ArrayList<>(list.size());
        for (BrandsEntity brand : list) {
            BrandModel brandModel = new BrandModel();
            brandModel.setId(brand.getId());
            brandModel.setName(brand.getName());
            brands.add(brandModel);
        }
        return R.ok(brands);
    }

    @GetMapping("/getCategories")
    @ApiOperation("获取类别列表")
    public R getCategories() {
        EntityWrapper<CategoriesEntity> ew = new EntityWrapper<>();
        ew.orderBy("id", true);
        List<CategoriesEntity> list = categoriesService.selectList(ew);
        return R.ok(list);
    }

    @GetMapping("/getBuyers")
    @ApiOperation("获取买手用户信息")
    public R getBuyers() {

        List<BuyerUser> list = usersService.getBuyers();
        return R.ok(list);
    }


    @GetMapping("/getTagHosts")
    @ApiOperation("获取热门标签")
    public R getTagHosts() {
        EntityWrapper<TagHotEntity> ew = new EntityWrapper<>();
        ew.orderBy("id", true);
        List<TagHotEntity> list = tagHotService.selectList(ew);
        List<TagHotModel> tagHots = new ArrayList<>(list.size());
        for (TagHotEntity tagHot : list) {
            TagHotModel tagHotModel = new TagHotModel();
            tagHotModel.setId(tagHot.getId());
            tagHotModel.setName(tagHot.getName());
            tagHots.add(tagHotModel);
        }
        return R.ok(tagHots);
    }

    @GetMapping("/getTagStyles")
    @ApiOperation("获取风格标签")
    public R getTagStyles() {
        EntityWrapper<TagStyleEntity> ew = new EntityWrapper<>();
        ew.orderBy("id", true);
        List<TagStyleEntity> list = tagStyleService.selectList(ew);
        List<TagStyleModel> tagStyles = new ArrayList<>(list.size());
        for (TagStyleEntity tagStyle : list) {
            TagStyleModel tagStyleModel=new TagStyleModel();
            tagStyleModel.setId(tagStyle.getId());
            tagStyleModel.setName(tagStyle.getName());
            tagStyles.add(tagStyleModel);
        }
        return R.ok(tagStyles);
    }

    /*@Autowired
    private ISmsService iSmsService;

    @GetMapping("/sms/notie")
    @ApiOperation("发生验证码")
    public R sendMessage() {
        try {

//            String code = ToolUtil.makeCode(4);
//            JSONObject smsJson=new JSONObject();
//            smsJson.put("code",code);
//
//            SendSmsResponse sendResp = null;
//
//            //国内短信
//            sendResp = AlidayuUtil.send("18006245150", AlidayuConstant.SIGN_NAME, AlidayuConstant.TEMPLATE_CODE_PHONE_BANK_BINGING, smsJson);
            iSmsService.sendPublishCheckRemind("18006245150","Gucci 包");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return R.ok();
    }*/
}
